﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualPoint.Controls.Environments;
using VisualPoint.Controls.Models;

namespace VisualPoint.Controls.Actions
{
    // todo add IWPF
    // http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.editor.iwpftextview.aspx
    public class FileOpenAction : BaseAction
    {
        public FileOpenAction()
        {
            _ViewKind = DteConstants.vsViewKindCode;
        }

        public override string Name
        {
            get 
            {
                return "Open File";
            }
        }

        public override string Description
        {
            get 
            {
                return string.Format("{0} {1} {2} {3}", Project, Folder, FileName, ViewKind);
                
            }
        }

        public override string Help
        {
            get 
            {
                return "Opens a the editor window of a File";
            }
        }

        public override BaseActionModel CreateModel()
        {
            return new FileOpenActionModel() { Action = this };
        }

        public bool ActiveDocument { get; set; }

        private string _project;
        public string Project 
        {
            get
            {
                return _project;
            }
            set
            {
                if (_project != value)
                {
                    _project = value;
                    DoPropertyChanged("Project");
                    DoDescriptionChanged();
                }
            }
        }

        private string _fileName;
        public string FileName
        {
            get
            {
                return _fileName;
            }
            set
            {
                if (_fileName != value)
                {
                    _fileName = value;
                    DoPropertyChanged("FileName");
                    DoDescriptionChanged();
                }
            }
        }

        private string _folder;
        public string Folder
        {
            get
            {
                return _folder;
            }
            set
            {
                if (_folder != value)
                {
                    _folder = value;
                    DoPropertyChanged("Folder");
                    DoDescriptionChanged();
                }
            }
        }

        private string _ViewKind;
        public string ViewKind
        {
            get
            {
                return _ViewKind;
            }
            set
            {
                if (_ViewKind != value)
                {
                    _ViewKind = value;
                    DoPropertyChanged("ViewKind");
                    DoDescriptionChanged();
                }
            }
        }

        private bool _SelectInExplorer;
        public bool SelectInExplorer
        {
            get
            {
                return _SelectInExplorer;
            }
            set
            {
                if (_SelectInExplorer != value)
                {
                    _SelectInExplorer = value;
                    DoPropertyChanged("SelectInExplorer");
                    DoDescriptionChanged();
                }
            }
        }

        public override void InitializeNew()
        {
            ViewKind = DteConstants.vsViewKindCode;
        }

        public override void Run()
        {
            VisualPoint.Controls.Environments.Environment.Current.OpenDocument(Project, Folder, FileName, ViewKind, SelectInExplorer);
        }
    }
}
